﻿using System.Diagnostics.Contracts;

namespace O1.Data.Traversal.Expressions
{
    [ContractVerification(true)]
    internal class PortableExpression : Filter
    {
        //// The point of this implementation is to limit how expressions are serialized and messaged to servers.
        //// Binary serialization of a delegate will pull in all closures; this is a performance risk and also can fail if
        //// the implementor doesn't know to make all involved classes serializable. A custom DSL allows for expression encoding and 
        //// rehydration without unexpected closures. Implementors will not know about this underpinning and will have a more 
        //// expressive API that is translated. A nice side effect is compactness and cache-ability of the binary encoded expression.
        //// And...yes, IEquatable<T> and IComparable<T> could allow generic definition here, but:
        //// . the semantics of comparing keys is always equality, which is awkward for IComparable<T>
        //// . an interface would be required to uniformly identify "Key" accross all data types (not a huge problem)
        //// . the delegates returned are expected to be in an extremely hot path, and interface indirection is slower than callvirt 
        //// Another approach considered was to serialize IL, however this exposes a security risk of executing arbitrary code.
        //// Ultimately, the choice here is to define a symbolic DSL and explicitly code it up, with minimal cleverness; plain ol' OO.

        private readonly byte operand;

        protected PortableExpression(byte portableOperand)
            : base()
        {
            this.operand = portableOperand;
        }

        public byte Operand 
        {
            get
            { 
                return this.operand;
            } 
        }
    }
}
